<template>
    <view class="top">
        <view class="code">{{ props.num }}</view>
        <view class="detail" v-if="props.islast == 0">
            还差<text class="number color">{{ props.all - props.num }}</text
            >成长值即可升级至{{ props.nextName }}哦~
        </view>
        <view class="detail" v-else><view class="detail">恭喜你，你已达 最高等级~</view></view>
        <view class="rule color" @click="popup.open('center')">规则说明</view>
    </view>
    <view class="table" v-if="detailData.length">
        <view class="row" v-for="(item, index) in detailData" :key="index">
            <view class="line">
                <text class="proname">{{
                    item.changeTypeName ? item.changeTypeName : item.changeType == 1 ? '购买商品' : '成长值变动'
                }}</text>
                <text class="count">
                    {{ item.changeValType == 1 ? '+' + item.changeVal : '-' + item.changeVal }}
                </text>
            </view>
            <view class="time">{{ item.updatedAt }}</view>
        </view>
    </view>
    <uni-popup ref="popup">
        <view class="popup">
            <view class="dialog">
                <view class="desc">规则说明</view>
                <view class="name">订单确认收货后，立即发放成长值。按照订单商品金额计算成长值，不包含运费部分。</view>
            </view>
            <img :src="getImgOssUrl('/ui-prod-2.4.0/cancel.png')" class="cancel" @click="popup.close()" />
        </view>
    </uni-popup>
</template>
<script setup>
import { ref, reactive } from 'vue';
import { onShow, onReachBottom } from '@dcloudio/uni-app';
import request from '@/request';
import { getImgOssUrl } from '@/commons/utils.js';
import storage from '@/commons/storage';
const props = defineProps(['id', 'all', 'num', 'islast', 'nextName']);
let detailData = ref([]);
const popup = ref();
let page = reactive({ page: 1, perPage: 8 });
let totalCount = ref(0);
onShow(async () => {
    const { data } = await request('experienceList', { ...page, openKid: storage.get('openKid') });
    detailData.value = data.list;
});
// 上拉加载
onReachBottom(() => {
    if (totalCount.value < detailData.value.length) {
        getData();
    }
});
const getData = async () => {
    const { data } = await request('experienceList', { ...page, openKid: storage.get('openKid') });
    page.page++;
    totalCount.value = data.totalCount;
    detailData.value = [...detailData.value, ...data.list];
};
</script>
<style lang="scss" scoped>
.popup {
    position: relative;
    width: 649rpx;
    background: #ffffff;
    border-radius: 22rpx;
    box-sizing: border-box;
    padding: 45rpx 54rpx;

    .desc {
        text-align: center;
        font-size: 25rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
        line-height: 40rpx;
    }
    .cancel {
        width: 54rpx;
        height: 54rpx;
        position: absolute;
        transform: translate(-50%, 0);
        bottom: -97rpx;
        left: 50%;
    }
    .dialog {
        display: flex;
        flex-direction: column;
        align-items: center;
        .logo {
            width: 101rpx;
            height: 101rpx;
        }
        .name {
            margin-top: 33rpx;
            font-size: 25rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            line-height: 40rpx;
        }
    }
}
.top {
    padding: 54rpx 29rpx;
    position: relative;
}
.code {
    height: 33rpx;
    margin-bottom: 18rpx;
    font-size: 51rpx;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 33rpx;
}
.color {
    color: #fe292b;
}
.rule {
    position: absolute;
    top: 29rpx;
    right: -2rpx;
    width: 118rpx;
    height: 43rpx;
    padding-left: 18rpx;
    line-height: 43rpx;
    background: #ffffff;
    border-radius: 27rpx 0 0 27rpx;
    border: 2rpx solid #fe292b;
    font-size: 22rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
}
.detail {
    height: 25rpx;
    font-size: 25rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
    line-height: 25rpx;
}
.table {
    background: #ffffff;
    padding: 29rpx;

    .row {
        border-bottom: 2rpx solid #f5f5f5;
        margin-bottom: 29rpx;
        &:last-child {
            border: none;
            margin-bottom: 0;
        }
        &:last-child .time {
            margin-bottom: 0;
        }
        .line {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 29rpx;
            &:last-child {
                margin-bottom: 0;
            }
            .proname {
                font-size: 31rpx;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                line-height: 31rpx;
            }
            .count {
                font-size: 31rpx;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #33302d;
                line-height: 31rpx;
            }
        }
        .time {
            font-size: 22rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 22rpx;
            margin-bottom: 29rpx;
        }
    }
}
</style>
